﻿using System;
using System.Collections.Generic;
using System.Text;
using XMK.Framework.Model.Ajax;
using XMK.Utils;
using XMK.Framework.Model;

namespace XMK.Framework.Web
{
    /// <summary>
    /// Ajax带权限认证统一入口
    /// </summary>
    public class AjaxMappingHandler : BaseHandler
    {
        /// <summary>
        /// 具体处理类
        /// </summary>
        /// <param name="responseInfo">返回至前台结果</param>
        protected override void ProcRequest(ref ResponseInfo responseInfo)
        {
            //前台不传递需要匹配的方法别名，则无法找到方法信息
            if (String.IsNullOrEmpty(this.RequestInfo.Type))
            {
                LogHelper.WriteLog(LogType.Error, "前台缺少必要的参数RequestType");
                responseInfo.State = 1;
                responseInfo.ErrMsg = "缺少参数RequestType！";
                return;
            }
            try
            {
                if (AjaxMappingHelper.GetAjaxMethod(RequestInfo.Type) != null)
                {
                    responseInfo = AjaxManager.Execute(this.RequestInfo);
                }
                else
                {
                    responseInfo = AjaxDataManager.Execute(this.RequestInfo);
                }
            }
            catch (Exception ex)
            {
                responseInfo.State = 1;
                responseInfo.ErrMsg = "未知错误:"+ex.Message;
                LogHelper.WriteLog(LogType.Error, "框架未知错误，详细信息：" + ex.ToString());
            }
        }
    }
}